package cn.crc.web.safe;

import cn.crc.web.tool.TestUserVo;
import cn.crc.web.tool.TestVipVo;
import cn.hutool.core.date.DateUtil;
import org.springframework.boot.CommandLineRunner;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.*;

public class WarnCacheData implements CommandLineRunner {
    public static List<TestUserVo> list1= new CopyOnWriteArrayList<>();
    public static Map<String, TestUserVo> map1= new ConcurrentHashMap<>();

    ScheduledExecutorService executorService= Executors.newSingleThreadScheduledExecutor();
    @Override
    public void run(String... args) throws Exception {
        List<TestUserVo> list11= TestVipVo.getUserTest();
        for(TestUserVo userVo: list11){
            map1.put(userVo.getTelephone(), userVo);
        }

        executorService.scheduleAtFixedRate(() -> {
            List<TestUserVo> list用户= TestVipVo.getUserTest();
            for(TestUserVo userVo: list用户){
                map1.put(userVo.getTelephone(), userVo);
            }
            WarnCacheData.testPrint();
        }, 0,5, TimeUnit.SECONDS);//TimeUnit.MINUTES 分钟
    }

    private static void testPrint(){
        Set set= map1.entrySet();
        for(Object entry: set){
            Map.Entry en= (Map.Entry) entry;
            System.out.println(DateUtil.now()+"\t"+ en.getKey()+";"+en.getValue());
        }
    }

}
